package org.opens.netty.chatServer.config;

import org.junit.Test;
import org.opens.netty.chatServer.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {

    public static final Properties PROPERTIES;

    static {
        try (InputStream in = Config.class.getResourceAsStream("/config.properties")) {
            PROPERTIES = new Properties();
            PROPERTIES.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    public static int getServerPort() {
        String serverPort = PROPERTIES.getProperty("server.port");
        if (serverPort == null) {
            return 8080;
        } else {
            return Integer.parseInt(serverPort);
        }
    }

    public static Serializer.Algorithm getSerializerAlgorithm() {
        String serializerAlgorithm = PROPERTIES.getProperty("serializer.algorithm");
        if (serializerAlgorithm == null) {
            return Serializer.Algorithm.Java;
        } else {
            return Serializer.Algorithm.valueOf(serializerAlgorithm);
        }
    }

    @Test
    public void name() {
        getSerializerAlgorithm();
    }
}
